<?php
namespace App\Repositories\Main;

use App\Models\Main\AdModel;
use App\Repositories\BaseRepository;

class AdRepository extends BaseRepository
{
//    protected $repository;

    public function __construct()
    {
        $this->repository = new AdModel();
    }

    public function getAdminIndex()
    {
        $models = $this->repository->paginate(10);
        $models->limit = 10;
        return $models;
    }

    public function getAppIndex($genre)
    {
        $models = $this->repository
            ->where('del',0)
            ->where('genre',$genre)
            ->orderBy('id','desc')
            ->limit(5)
            ->get()->toArray();
        if (!$models) { return ''; }
        return $models;
    }

    public function setAdd($data)
    {
        $data['created_at'] = time();
        return $this->repository->insertGetId($data);
    }

    public function setModify($data,$id)
    {
        $data['updated_at'] = time();
        return $this->repository->where('id',$id)
            ->update($data);
    }

    public function getShowOne($id)
    {
        return $this->repository->where('id',$id)->first();
    }

    public function getGenres()
    {
        return $this->repository->getGenres();
    }
}